class SearchController < ApplicationController
  helper_method :sort_column, :sort_direction

  def search 
    @search_text = params[:search]
    @results = Book.search_by(@search_text, params[:page],
                             params[:sort], params[:direction])

    respond_to do |format|
      format.html
    end
  end

  protected

  def sort_column
    Book.column_names.include?(params[:sort]) ? params[:sort] : "name"
  end

  def sort_direction
    %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
  end 
end

